package com.beiye.drivertransport.SubActivity;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.beiye.drivertransport.R;
import com.beiye.drivertransport.activity.TwoBaseAty;
import com.beiye.drivertransport.adapter.ImgLookAdapter;
import com.beiye.drivertransport.fragment.ImgFragment;

import java.util.ArrayList;
import java.util.List;



public class ImageLookActivity extends TwoBaseAty {

    private static final String TAG = "测试";

    ImageView acImgLookIvBack;

    TextView acImgLookTvIndex;

    ViewPager acImgLookVp;


    @Override
    public int getLayoutId() {
        return R.layout.activity_img_look;

    }

    @Override
    public void initData() {
        acImgLookIvBack = (ImageView) findViewById(R.id.ac_imgLook_iv_back);
        acImgLookTvIndex = (TextView) findViewById(R.id.ac_imgLook_tv_index);
        acImgLookVp = (ViewPager) findViewById(R.id.ac_imgLook_vp);

        int position = getIntent().getIntExtra("position", 1);
        final ArrayList<String> imgs = getIntent().getStringArrayListExtra("imgs");

        acImgLookIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        acImgLookTvIndex.setText(position + "/" + imgs.size());

        List<Fragment> fragmentList = new ArrayList<>();
        for (int i = 0; i < imgs.size(); i++) {
            fragmentList.add(new ImgFragment().newIntent(imgs.get(i)));
        }

        ImgLookAdapter adapter = new ImgLookAdapter(getSupportFragmentManager(), this, fragmentList);
        acImgLookVp.setAdapter(adapter);
        acImgLookVp.setCurrentItem(position - 1);

        acImgLookVp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                acImgLookTvIndex.setText((i + 1) + "/" + imgs.size());
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }

    @Override
    public void requestData() {

    }

}
